<template>
  <div>
    <teleport to="body">
      <Transition name="fade">
        <div
          v-if="isVisible"
          @click="isVisible = false"
          class="w-screen h-screen bg-zinc-900/90 z-40 fixed top-0 left-0"
        ></div>
      </Transition>
      <transition name="popup-down-up">
        <div
          v-if="isVisible"
          v-bind="$attrs"
          class="w-screen bg-white z-50 dark:bg-zinc-800 fixed bottom-0"
        >
          <slot />
        </div>
      </transition>
    </teleport>
  </div>
</template>

<script setup>
import { useScrollLock, useVModel } from '@vueuse/core'
import { watch } from 'vue'
const props = defineProps({
  modelValue: {
    type: Boolean,
    required: true
  }
})
const isVisible = useVModel(props)
const isLock = useScrollLock(document.body)
defineEmits(['update:modelValue'])
watch(isVisible, (val) => {
  isLock.value = val
})
</script>

<style lang="scss" scoped>
.fade-enter-active,
.fade-leave-active {
  transition: all 0.3s;
}
.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}
// popup-down-up 展示动画
.popup-down-up-enter-active {
  transition: all 0.3s;
}
.popup-down-up-leave-active {
  transition: all 0.3s;
}
.popup-down-up-enter-from,
.popup-down-up-leave-to {
  transform: translateY(100%);
}
</style>
